package day2001;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.*;

public class fanshe {
    public static void main(String[] args) throws Exception {
//        com1();//操作成员变量
//        com2();//操作成员方法
        com3();//构造方法
    }

    private static void com3() throws Exception {
        Class a = anli.class;
        Constructor b=a.getConstructor();
        b.newInstance();
        Constructor c=a.getConstructor(int.class,String.class,int.class);
        c.newInstance(1,"2",3);
    }

    private static void com2() throws Exception {
        Class a = anli.class;
        Method b = a.getMethod("xin_xi", int.class, int.class, String.class);
        Object c =a.newInstance();
        b.invoke(c,10,30,"qwert");
    }

    private static void com1() throws Exception {
        Class a = anli.class;
        Field[] b = a.getFields();
        Object ss = a.newInstance();
        for(Field x : b){
            System.out.println(x.getName());
            if(x.getType().getName()=="int")
                x.set(ss,new Random().nextInt(1000));
            else
                x.set(ss,"aaaaa");
            System.out.println(x.get(ss));
        }
    }

}
